/*******************************************************************************
 * Copyright 2007, 2009 InnovaSoft SA http://www.innovasoft.biz/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
 
package biz.innovasoft.nodb.transaction;

import java.lang.reflect.Method;
import java.util.Date;

import org.prevayler.Transaction;

import biz.innovasoft.nodb.RepositoryException;

public class AnnotatedTransaction implements Transaction {

	private static final long serialVersionUID = 1L;

	private String method;
	private Object args[];
	private Class<?> types[];

	public AnnotatedTransaction() {
	}

	public AnnotatedTransaction(String method, Class<?>[] types, Object[] args) {
		this.method = method;
		this.args = args;
		this.types = types;
	}

	public void executeOn(Object pSystem, Date date) throws RuntimeException {
		try {
			Method _method = pSystem.getClass().getMethod(method, types);
			_method.invoke(pSystem, args);
		} catch (RepositoryException e) {
			throw e;
		} catch (Exception e) {
			throw new RuntimeException (e);
		}

	}

}
